package com.tkmybatis.controller;


import com.alibaba.fastjson.JSON;
import com.tkmybatis.domain.EptOrgResource;
import com.tkmybatis.hfy.base.entity.PageBean;
import com.tkmybatis.hfy.redis.RedisUtils;
import com.tkmybatis.service.EptOrgResourceService;
import com.tkmybatis.utils.SnowFlakeUtil;
import com.tkmybatis.vo.DemVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;

@RestController
@RequestMapping("/resource")
@Slf4j
@Api(tags = "获取组织资源的控制层")
public class EptOrgResourceController {

    @Autowired
    private EptOrgResourceService eptOrgResourceService;



    @GetMapping("/organ")
    @ApiOperation("列出组织详情")
    public List<EptOrgResource> listOrgResource(@RequestParam("parentId") String parentId){
        return eptOrgResourceService.listOrgResource(parentId);
    }

    @GetMapping("/page")
    @ApiOperation("分页列出组织详情")
    public PageBean<EptOrgResource> findListMapByParentId(@RequestParam(value = "parentId",required = true) String parentId, @RequestParam(value = "pageNum",required = false) Integer pageNum, @RequestParam(value = "pageSize",required = false)Integer pageSize){
        return eptOrgResourceService.findListMapByParentId(parentId,pageNum,pageSize);
    }


    @GetMapping("/averageSalary2")
    @ApiOperation("获取部门所有员工的平均工资")
    public List<DemVo> findSalaryByDempNum2(){
        return eptOrgResourceService.findSalaryByDempNum2();
    }

    @GetMapping("/count")
    @ApiOperation("获取部门总数量")
    public  Integer getByDepNo(){
        return  eptOrgResourceService.getByDepNo();
    }


    @GetMapping("/getXueHua")
    @ApiOperation("雪花算法获取key")
    public Map<String,String> getSnowFlake(){
        String xuehua = (String) RedisUtils.get("xuehua");
        if(xuehua==null || "".equals(xuehua)){
            RedisUtils.set("xuehua", SnowFlakeUtil.nextId());
        }
        HashMap<String,String> hashMap=new HashMap<>();
        hashMap.put("xuehua",(String)RedisUtils.get("xuehua"));
        return hashMap;
    }



}
